<script>
	import config from './config'
	import store from '@/store'
	import {
		getToken
	} from '@/utils/auth'
	import {
		upgradeCheck,
	} from '@/api/sys.js';
	export default {
		onLaunch: function() {
			this.initApp()
		},
		methods: {
			// 初始化应用
			initApp() {
				// 初始化应用配置
				this.initConfig()
				// 检查用户登录状态
				//#ifdef H5
				this.checkLogin()
				//#endif
		this.checkVesion()
			},
			initConfig() {
				this.globalData.config = config
			},
			checkLogin() {
				if (!getToken()) {
					this.$tab.reLaunch('/pages/login')
				}
			},
			checkVesion() {
				//#ifdef APP-PLUS
				// 获取本地应用资源版本号
				plus.runtime.getProperty(plus.runtime.appid, (info) => {
					// this.version = info.version;
					// console.log('版本version', this.version)
					upgradeCheck().then((response) => {
						//console.log(response)
						if (response.code == 200) {
							if (response.data.configKey != info.version) {
								uni.showModal({
									title: '提示',
									content: '检测到新版本，是否下载更新？',
									showCancel: true,
									success: function(res2) {
										if (res2.confirm) {
											plus.runtime.openURL(response.data.configValue);
										}
									}
								});
							}
						}
					});
				})
				//#endif
			}
		}
	}
</script>

<style lang="scss">
	@import '@/static/scss/index.scss';
	@import "@/static/iconfont.css";
</style>